"""
信息熵
信息增益 = 信息熵 - 条件熵
信息增益: 信息熵的减少程度
.dot文件的打开网站: http://webgraphviz.com
找到最高效的决策顺序 - 信息增益
准确率: 92%
"""
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier,export_graphviz

# 1 获取数据
iris = load_iris()
# 2 划分数据集
x_train,x_test,y_train,y_test = train_test_split(iris.data,iris.target,random_state=6)
# 3 决策树
estimator = DecisionTreeClassifier(criterion='entropy',max_depth=8)
estimator.fit(x_train,y_train)
# 4 模型评估
score = estimator.score(x_test,y_test)
print(score)
# 可视化决策树
export_graphviz(estimator,out_file='tree.dot',feature_names=iris.feature_names)
